package com.System.LearnSystemBasic;

import java.io.BufferedReader;
import java.io.IOException;

import com.System.LearnSystem.Token;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet("/Logout")
public class Logout extends HttpServlet{
	public void doDelete(HttpServletRequest req, HttpServletResponse res) throws IOException
	{
		StringBuilder json = new StringBuilder();//读取json请求
        BufferedReader reader = req.getReader();
        String line;
        while ((line = reader.readLine()) != null) {
            json.append(line);
        }
        String jsonStr = json.toString();
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());//注册驱动保证序列化
        Tk loout = objectMapper.readValue(jsonStr, Tk.class);
        Token.revokeToken(loout.getToken());
	}
}


class Tk
{
	private String token;

	public Tk()
	{
		
	}
	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}
}